package pluginUtils;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

public class HGTReader {
	private int rows,columns; 
	private int minTranche[],maxTranche[],valeurs[][]; 
	private int maxElevationInt=-32000,minElevationInt=5000; 
	
public int[][] getValeurs(){return valeurs;}
	
	public int[] getMinTranche() {
		return minTranche;
	}

	public int[] getMaxTranche() {
		return maxTranche;
	}
	
	public int getColumns() {
		return columns;
	}

	public int getMinTranche(int i) {
		return minTranche[i];
	}

	public int getMaxTranche(int i) {
		return maxTranche[i];
	}

	public int[] getSlice(int k){return valeurs[k]; }	
	
	

	public int getMaxElevationInt() {
		return maxElevationInt;
	}

	public int getMinElevationInt() {
		return minElevationInt;
	}

	
	public void readData(String nomFichierSource){
		 try {
			 File temp=new File(nomFichierSource); 
			 if(temp.length()==2884802)
			 {rows=1201; columns=1201;}
			 else throw new Exception("size not handled");
			 System.out.println(temp.length()); 
		     valeurs=new int[rows][columns]; 
		     minTranche=new int[rows]; 
		     maxTranche=new int[columns]; 
             DataInputStream in = new DataInputStream(new FileInputStream(nomFichierSource));
             for(int i=0;i<1201;i++){
            	 	int mini=5000; 
            	 	int maxi=-30000; 
            	 	for(int j=0;j<1201;j++){
            	 	short val=in.readShort();
            	 	if(val==-32768) val=0; 
            	 	if(val<mini)mini=val; 
            	 	if(val>maxi) maxi=val; 
            	 	valeurs[i][j]=val; 
            	 	}//j
            	 	minTranche[i]=mini; 
            	 	maxTranche[i]=maxi; 
            	 	if(minTranche[i]<minElevationInt)minElevationInt=minTranche[i];
            	 	if(maxTranche[i]>maxElevationInt)maxElevationInt=maxTranche[i];
            	 	 
             }//i
             
           	 
	}
		 catch (Exception e) {
			System.out.println("Probleme : "+e.getMessage()); System.exit(0); 
		}
	
}
	
	public static void main(String[] args) {
		HGTReader toto=new HGTReader(); 
		toto.readData("C:/Users/decomite/Downloads/N00E097.hgt/N00E097.hgt"); 
		
	}

}